//
//  WCExtractImg.m
//  WebClipper
//
//  Created by Daniel Braun on 03/05/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "WCExtractImg.h"


@implementation WCExtractImg

+ (NSString *) description
{
	return @"extract img";
}

- (void) dealloc {
	[super dealloc];
}

- (id) init {
	self = [super init];
	if (self != nil) {
	}
	return self;
}

- (id) initWithCoder:(NSCoder *) coder
{
	self=[super initWithCoder:coder];
	if ([coder allowsKeyedCoding]) {
	}
	return self;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
	[super encodeWithCoder:coder];
	if ( [coder allowsKeyedCoding] ) {
	}
}


- (id) handle:(DOMHTMLElement *)el  fromUrl:(NSURL *)url
{
	if (![[[el nodeName] lowercaseString]isEqualToString:@"img"]) {
		NSLog(@"looking for element in  %@\n", [el nodeName]);
		if ([el respondsToSelector:@selector(getElementsByTagName:)]) {
			el=(DOMHTMLElement *)[[el getElementsByTagName:@"img"]item:0];
		} else {
			NSLog(@"not a DOMelement? (%@)\n", el);
			return nil;
		}
	}
	if (!el) return nil;
	NSString *src=[el getAttribute:@"src"];
	NSURL *nurl=[NSURL URLWithString:src relativeToURL:url] ;
	NSLog(@"got url %@ (%@)\n", nurl, [nurl absoluteString]);
	return [nurl absoluteString];
}

@end
